package sanrenxing.dayEnd.backRepertoryTotal.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sanrenxing.dayEnd.backRepertoryTotal.dao.SecuritiesStockDao;
import sanrenxing.dayEnd.backRepertoryTotal.domain.SecuritiesStock;
import sanrenxing.dayEnd.backRepertoryTotal.domain.SecuritiesStockTwo;
import sanrenxing.dayEnd.backRepertoryTotal.service.SecuritiesStockBiz;

import java.util.HashMap;
import java.util.List;

/**
 * 功能：证券库存表的业务层实现类
 * 作者：赵思睿
 * 日期：2021/3/12 0012-15:00
 * 版本：1.0
 */
@Service("secStockBiz")
public class SecuritiesStockBizImpl implements SecuritiesStockBiz {
    @Autowired
    private SecuritiesStockDao secStockDao;

    /**
     * 将证券库存信息添加到数据库表中
     *
     * @param securitiesStock 证券库存对象
     * @return 1：添加成功；0：添加失败
     */
    @Override
    public int add(SecuritiesStock securitiesStock) {
        return secStockDao.add(securitiesStock);
    }

    /**
     * 根据证券库存编号删除证券库存信息
     *
     * @param secId 证券库存编号
     * @return 1：删除成功；0：删除失败
     */
    @Override
    public int delete(String secId) {
        if(secId.contains(",")){
            //对证券库存编号字符串进行分割
            String[] strs=secId.split(",");
            //循环删除
            for(String str:strs){
                secStockDao.delete(str);
            }
            return 1;

        }else {
            return secStockDao.delete(secId);
        }
    }

    /**
     * 按条件进行分页查询
     *
     * @param secStock 证券库存对象
     * @param row      每页行数
     * @param page     页数
     * @return 证券库存对象集合
     */
    @Override
    public List<SecuritiesStockTwo> selectAll(SecuritiesStock secStock, int row, int page) {
        HashMap<String,Object> map=new HashMap<>();
        map.put("secStock",secStock);
        map.put("start",page);
        map.put("end",(page+row));
        return secStockDao.selectAll(map);
    }

    /**
     * 按查询条件统计记录数
     *
     * @param secStock
     * @return 统计行数
     */
    @Override
    public int count(SecuritiesStock secStock) {
        return secStockDao.count();
    }
}
